home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MSHENT.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  3KB  |  101 lines

  1. /*  mshent.c    -- show an entry from a Minix file directory */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved. */
  3. /*  $Header: MSHENT.C_V 1.3 91/03/19 13:23:33 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <string.h>
  7. #include    <time.h>
  8. #include    "mfs.h"
  9.  
  10.  
  11. /*==================================================================*/
  12. void show_ent (iarea, dp)
  13. struct inode        *iarea ;
  14. struct directory    *dp ;
  15. {
  16.     int         i, j, k, n ;
  17.     struct inode    *ip ;
  18.     char        c, decode[11] ;
  19.     ushort      mode ;
  20.     struct tm   *tp ;
  21.  
  22.     strcpy (decode, "----------") ;
  23.  
  24.     if (!(n = dp->d_inum)) /*assignok*/
  25.         return ;
  26.     ip = &iarea[n] ;
  27.  
  28. /*  Decode the first character of permissions string
  29.  */
  30.     if (!(ip->i_mode & I_REGULAR))
  31.     {
  32.         mode = ip->i_mode & I_TYPE ;
  33.         if (mode == I_BLOCK_SPECIAL)
  34.             decode[0] = 'b' ;
  35.         else if (mode == I_DIRECTORY)
  36.             decode[0] = 'd' ;
  37.         else if (mode == I_CHAR_SPECIAL)
  38.             decode[0] = 'c' ;
  39.         else
  40.             decode[0] = '?' ;
  41.     }
  42.  
  43. /*  Decode the rwx permissions
  44.  */
  45.     mode = ip->i_mode & RWX_MODES ;
  46.  
  47.     for (i=2; i>=0; i--, mode>>3)
  48.     {
  49.         if (mode & R_BIT)
  50.             decode[3*i+1] = 'r' ;
  51.         if (mode & W_BIT)
  52.             decode[3*i+2] = 'w' ;
  53.         if (mode & X_BIT)
  54.             decode[3*i+3] = 'x' ;
  55.     }
  56.  
  57.     if (ip->i_mode & I_SET_UID_BIT)
  58.     {
  59.         if (decode[3] == 'x')
  60.             decode[3] = 's' ;
  61.         else
  62.             decode[3] = 'S' ;
  63.     }
  64.  
  65.     if (ip->i_mode & I_SET_GID_BIT)
  66.     {
  67.         if (decode[6] == 'x')
  68.             decode[6] = 's' ;
  69.         else
  70.             decode[6] = 'S' ;
  71.     }
  72.  
  73.     printf ("%s ", decode) ;
  74.  
  75. /*  Supply numerical info from the inode
  76.  */
  77.     printf ("%3uL %5dI %3uU %3uG %9lu ", (ushort)ip->i_nlinks, n,
  78.                                          ip->i_uid, ip->i_gid,
  79.                                          ip->i_size ) ;
  80.  
  81. /*  Display timestamp of last modification
  82.  */
  83.     tp = localtime (&(ip->i_modtime)) ;
  84.     printf ("%02d/%02d/%02d %02d:%02d:%02d  ", tp->tm_year,
  85.                                                tp->tm_mon+1,
  86.                                                tp->tm_mday,
  87.                                                tp->tm_hour,
  88.                                                tp->tm_min,
  89.                                                tp->tm_sec );
  90.  
  91. /*  Display the unadorned filename
  92.  */
  93.     for (i=0; (i<NAME_SIZE) && (c=dp->d_name[i]); i++) /*assignok*/
  94.         printf ("%c", c) ;
  95.     printf ("\n") ;
  96.  
  97. } /* show_ent() */
  98.  
  99.  
  100. /*---eof---*/
  101.